import { Button, Tooltip } from 'antd';
import { Fragment } from 'react';
import { ProjectOutlined, MonitorOutlined, ContainerOutlined } from '@ant-design/icons';
import { getUserID, renderTableText, tableSorter, tooltipLength, priceFormat } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { ManageCommonAPI } from '@/pages/type';
import { tableMoreBtnConfig } from '@/utils/myutilConfig';

// 操作按钮
const Operation = (curRes: Record<string, any>, clickFnc: ContractCheckManageAPI.IOperationClick, record: Record<string, any>, tabSwitchType: string) => {
  let operationArray: any = [];

  /** 一个按钮都没有时展示*/
  const Disable = (
    <Fragment key={record?.id + '--Disable'}>
      <Button style={{ color: '#000' }} className="manageBtntTxtStyle" type={'link'} size={'small'} disabled>
        --
      </Button>
    </Fragment>
  );

  /** 更多按钮配置 */
  const otherBtnConfig: ManageCommonAPI.TableMoreBtnConfigApi[] = [
    // {
    //   icon: <ContainerOutlined />,
    //   btnName: 'OA',
    //   clickFnc: clickFnc,
    //   clickType: 'onOA',
    //   isVisible: true,
    // },
    // {
    //   icon: <ProjectOutlined />,
    //   btnName: '办理',
    //   clickFnc: clickFnc,
    //   clickType: 'onHand',
    //   isVisible: curRes?.['/contractController/complete'] && record?.receiver == getUserID() && record.suspendState == 1 && tabSwitchType == 'NeedToDoTasks',
    // },
    // {
    //   icon: <MonitorOutlined />,
    //   btnName: '进度',
    //   clickFnc: clickFnc,
    //   clickType: 'onStep',
    //   isVisible: curRes?.['/contractController/getImageByProcInstID/{procInstID}'] && tabSwitchType == 'NeedToDoTasks',
    // },
  ];

  const ohterBtn = tableMoreBtnConfig(otherBtnConfig, record);

  operationArray = ohterBtn;
  operationArray = operationArray?.filter((itemBtn: any) => itemBtn);
  return operationArray && operationArray?.length > 0 ? operationArray : [Disable];
};

const getTableColumns = (curRes: Record<string, any>, clickFnc: ContractCheckManageAPI.IOperationClick, tabSwitchType: string | any) => {
  let config: Record<string, any>[] = [
    {
      title: '标题',
      dataIndex: 'subject',
      key: 'subject',
      width: 170,
      visible: 'allTask',
      fixed: 'left',
      sorter: (a: any, b: any) => (a?.subject > b?.subject ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        const showText: string | null = text;
        return (
          <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>
              <a
                onClick={() => {
                  clickFnc?.onOA(record);
                }}
              >
                {showText ? showText : '--'}
              </a>
            </span>
          </Tooltip>
        );
      },
    },
    {
      title: '类型',
      dataIndex: 'defName',
      key: 'defName',
      width: 100,
      visible: 'allTask',
      sorter: (a: any, b: any) => (a?.defName > b?.defName ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        const changeWay: string | null = record?.defName;
        let showText: string | null = changeWay;
        return (
          <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '当前环节',
      dataIndex: 'nodeName',
      key: 'nodeName',
      visible: 'allTask',
      width: 170,
      sorter: (a: any, b: any) => tableSorter(a, b, 'nodeName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '时间',
      dataIndex: 'createDateTime',
      key: 'createDateTime',
      width: 160,
      visible: 'notTask',
      sorter: (a: any, b: any) => tableSorter(a, b, 'createDateTime'),
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '发送人',
      dataIndex: 'creatorName',
      key: 'creatorName',
      width: 100,
      visible: 'notTask',
      sorter: (a: any, b: any) => (a?.creatorName > b?.creatorName ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        const showText: string | null = record?.creatorName;
        return (
          <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '办理时间',
      dataIndex: 'endTime',
      key: 'endTime',
      width: 160,
      visible: 'handTask',
      sorter: (a: any, b: any) => tableSorter(a, b, 'endTime'),
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '办理人',
      dataIndex: 'receiverName',
      key: 'receiverName',
      width: 100,
      visible: 'handTask',
      sorter: (a: any, b: any) => (a?.receiverName > b?.receiverName ? 1 : -1),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '办理结果',
      dataIndex: 'resultInfo',
      key: 'resultInfo',
      width: 120,
      visible: 'handTask',
      sorter: (a: any, b: any) => (a?.resultInfo > b?.resultInfo ? 1 : -1),
      render: (text: string) => renderTableText(text, true),
    },
    // {
    //   title: '操作',
    //   dataIndex: 'operation',
    //   key: 'operation',
    //   width: tabSwitchType == 'NeedToDoTasks' ? 120 : 80,
    //   visible: true,
    //   unDrag: true,
    //   fixed: 'right',
    //   isShowTask: 'allTask',
    //   render: (_text: any, record: any) => {
    //     return <div style={{ display: 'flex' }}>{Operation(curRes, clickFnc, record, tabSwitchType)}</div>;
    //   },
    // },
  ];

  /** 根据标识区分待办和已办，返回不同的columns */
  let newColumns: Record<string, any>[] = config?.filter((item: any) =>
    tabSwitchType == 'NeedToDoTasks' ? item?.visible != 'handTask' : item?.visible != 'notTask',
  );

  return newColumns;
};

export { getTableColumns };

// let config: Record<string, any>[] = [
//   {
//     title: '合同名称',
//     dataIndex: 'attributes.busi_contractName',
//     key: 'attributes.busi_contractName',
//     width: 230,
//     visible: true,
//     fixed: 'left',
//     unDrag: true,
//     isShowTask: 'allTask',
//     sorter: (a: any, b: any) => (a?.attributes.busi_contractName > b?.attributes.busi_contractName ? 1 : -1),
//     render: (text: string | null, record: Record<string, any>) => {
//       const showText: string | null = record?.attributes?.busi_contractName;
//       return (
//         <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
//           <span className={pageStyles['over-flow-hidden']}>
//             <a
//               onClick={() => {
//                 clickFnc?.onView(record);
//               }}
//             >
//               {showText ? showText : '--'}
//             </a>
//           </span>
//         </Tooltip>
//       );
//     },
//   },
//   {
//     title: '任务类型',
//     dataIndex: 'attributes.busi_changeWay',
//     key: 'attributes.busi_changeWay',
//     width: 150,
//     visible: true,
//     isShowTask: 'allTask',
//     sorter: (a: any, b: any) => (a?.attributes.busi_changeWay > b?.attributes.busi_changeWay ? 1 : -1),
//     render: (text: string | null, record: Record<string, any>) => {
//       const changeWay: string | null = record?.attributes.busi_changeWay;
//       let showText: string = '合同申请';
//       if (changeWay == '0') {
//         showText = '合同变更';
//       } else if (changeWay == '1') {
//         showText = '合同解除';
//       }
//       return (
//         <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
//           <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
//         </Tooltip>
//       );
//     },
//   },
//   {
//     title: '当前环节',
//     dataIndex: 'taskName',
//     key: 'taskName',
//     visible: true,
//     width: 230,
//     isShowTask: 'allTask',
//     sorter: (a: any, b: any) => tableSorter(a, b, 'taskName'),
//     render: (text: string) => renderTableText(text, true),
//   },
//   {
//     title: '时间',
//     dataIndex: 'createTime',
//     key: 'createTime',
//     width: 160,
//     visible: true,
//     isShowTask: 'notTask',
//     sorter: (a: any, b: any) => tableSorter(a, b, 'createTime'),
//     render: (text: string, record: Record<string, any>) => {
//       return (
//         <Tooltip title={text ? text : ''}>
//           <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//         </Tooltip>
//       );
//     },
//   },
//   {
//     title: '发送人',
//     dataIndex: 'attributes.busi_ownerName',
//     key: 'attributes.busi_ownerName',
//     width: 150,
//     visible: true,
//     isShowTask: 'notTask',
//     sorter: (a: any, b: any) => (a?.attributes.busi_ownerName > b?.attributes.busi_ownerName ? 1 : -1),
//     render: (text: string | null, record: Record<string, any>) => {
//       const showText: string | null = record?.attributes.busi_ownerName;
//       return (
//         <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
//           <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
//         </Tooltip>
//       );
//     },
//   },
//   {
//     title: '办理时间',
//     dataIndex: 'endTime',
//     key: 'endTime',
//     width: 160,
//     visible: true,
//     isShowTask: 'handTask',
//     sorter: (a: any, b: any) => tableSorter(a, b, 'endTime'),
//     render: (text: string, record: Record<string, any>) => {
//       return (
//         <Tooltip title={text ? text : ''}>
//           <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
//         </Tooltip>
//       );
//     },
//   },
//   {
//     title: '办理人',
//     dataIndex: 'assigneeName',
//     key: 'assigneeName',
//     width: 150,
//     visible: true,
//     isShowTask: 'handTask',
//     sorter: (a: any, b: any) => (a?.assigneeName > b?.assigneeName ? 1 : -1),
//     render: (text: string) => renderTableText(text, true),
//   },
//   {
//     title: '办理结果',
//     dataIndex: 'resultInfo',
//     key: 'resultInfo',
//     width: 150,
//     visible: true,
//     isShowTask: 'handTask',
//     sorter: (a: any, b: any) => (a?.resultInfo > b?.resultInfo ? 1 : -1),
//     render: (text: string) => renderTableText(text, true),
//   },
//   {
//     title: '操作',
//     dataIndex: 'operation',
//     key: 'operation',
//     width: tabSwitchType == 'NeedToDoTasks' ? 230 : 90,
//     visible: true,
//     unDrag: true,
//     fixed: 'right',
//     isShowTask: 'allTask',
//     render: (_text: any, record: any) => {
//       return (
//         <div
//           style={{
//             display: 'flex',
//           }}
//         >
//           {Operation(curRes, clickFnc, record, tabSwitchType)}
//         </div>
//       );
//     },
//   },
// ];
